package LeetCode.leetcode78;

import java.util.ArrayList;
import java.util.List;

public class Solution {
    public List<List<Integer>> subsets(int[] nums) {
        List<List<Integer>> res = new ArrayList<>();
        List<Integer> path = new ArrayList<>();
        if (nums.length == 0)
            return res;
        backTracking(res, path, 0, nums);
        return res;
    }

    public static void backTracking(List<List<Integer>> res, List<Integer> path, int startIndex, int[] nums) {
        res.add(new ArrayList<>(path));
        if (startIndex == nums.length) {
            return;
        }
        for (int i = startIndex; i < nums.length; i++) {
            path.add(nums[i]);
            backTracking(res, path, i + 1, nums);
            path.remove(path.size()-1);
        }
    }
}
